package com.rrd.hive.udf;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;


public class NumberRSAUDF extends UDF{
//	private static final char[] dictionary = "9876543210".toCharArray();
	private static final char[] dictionary = "6789541230".toCharArray();
	public Text evaluate(String mobile) {
		Text text = new Text();
		if(mobile==null || mobile.equals("")){
			return null;
		} 
		StringBuilder sb = new StringBuilder(mobile.substring(0,3));
		String s2=mobile.substring(3);
		char[] arr =s2.toCharArray();
		for(int i=0;i<arr.length;i++){
			 
			if(Character.isDigit(arr[i])){
				sb.append(dictionary[Integer.parseInt(String.valueOf(arr[i]))]);
			}else{
				sb.append(arr[i]);
			}
		}
		text.set(sb.toString());
		return text;
	}
	

public static void main(String[] args) {
	TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");  
    df.setTimeZone(tz);  
    Date date = new Date();
    String nowAsISO = df.format(date);  
    System.out.println(nowAsISO);
}
   
}
